﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsAppTest.Control;
using WinFormsAppTest.Dao;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace WinFormsAppTest
{
    public partial class AdminForm : Form
    {
        //
        public String adminname = "null";//设置默认登录用户(手动添加)
        public int id = 0;//设置默认登录用户(手动添加)
        //
        public AdminForm()
        {
            InitializeComponent();
        }

        public AdminForm(String name, int uid)
        {
            adminname = name;
            id = uid;
            InitializeComponent();
            Adminlabel.Text = adminname;
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            //timelabel.Text = DateTime.Now.ToString("G");
        }

        private void AdminForm_Closing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                // 关闭进程
                Process.GetCurrentProcess().Kill();
            }
        }

        private void AdminForm_Load(object sender, EventArgs e)
        {
            timer1.Interval = 1000;
            timer1.Start();
            if (adminname == "null")
            {
                MessageBox.Show("管理员为空，即将返回到主界面！");
                Form1 f = new Form1();
                this.Hide();
                f.ShowDialog();
                this.Dispose();
            }
            else if (adminname == "user" && id != 0)
            {
                AdminDao adminDao = new AdminDao();

                Form2 f = new Form2(adminDao.GetUserById(id)[0].Name, id);
                this.Hide();
                f.ShowDialog();
                this.Dispose();
            }
        }

        private void Exitbutton_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form1 f = new Form1();
            f.ShowDialog();
            this.Dispose();
        }

        private void UserMaToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void UserManage_Click(object sender, EventArgs e)
        {
            this.Hide();
            UserForm f = new UserForm(adminname, id);
            f.ShowDialog();
            this.Dispose();
        }

        private void AdminManage_Click(object sender, EventArgs e)
        {
            this.Hide();
            AdminManageForm f = new AdminManageForm(adminname, id);
            f.ShowDialog();
            this.Dispose();
        }

        private void FilesManage_Click(object sender, EventArgs e)
        {
            this.Hide();
            FilesForm f = new FilesForm(adminname, id);
            f.ShowDialog();
            this.Dispose();
        }

        private void ChangeManage_Click(object sender, EventArgs e)
        {
            this.Hide();
            ChangeForm f = new ChangeForm(adminname, id);
            f.ShowDialog();
            this.Dispose();
        }

        private void ExamManage_Click(object sender, EventArgs e)
        {
            this.Hide();
            ExamForm f = new ExamForm(adminname, id);
            f.ShowDialog();
            this.Dispose();
        }

        private void OuttimeManage_Click(object sender, EventArgs e)
        {
            this.Hide();
            OuttimeForm f = new OuttimeForm(adminname, id);
            f.ShowDialog();
            this.Dispose();
        }

        private void SignsManage_Click(object sender, EventArgs e)
        {
            this.Hide();
            SignsForm f = new SignsForm(adminname, id);
            f.ShowDialog();
            this.Dispose();
        }

        private void OvertimeManage_Click(object sender, EventArgs e)
        {
            this.Hide();
            OvertimeForm f = new OvertimeForm(adminname, id);
            f.ShowDialog();
            this.Dispose();
        }

        private void AdmintreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (AdmintreeView.SelectedNode.Text == "首页")
            {
                //MessageBox.Show("首页");
                datapanel.Controls.Clear();
                datapanel.Controls.Add(pictureBox1);
            }
            else if (AdmintreeView.SelectedNode.Text == "个人档案查询")
            {
                //MessageBox.Show("个人档案");
                datapanel.Controls.Clear();
                FilesSearchControl f = new FilesSearchControl();
                datapanel.Controls.Add(f);
            }
            else if (AdmintreeView.SelectedNode.Text == "个人档案处理")
            {
                //MessageBox.Show("个人档案");
                this.Hide();
                FilesForm f = new FilesForm(adminname, id);
                f.ShowDialog();
                this.Dispose();
            }
            else if (AdmintreeView.SelectedNode.Text == "个人人事变动查询")
            {
                //MessageBox.Show("个人档案");
                datapanel.Controls.Clear();
                ChangeSearchControl f = new ChangeSearchControl();
                datapanel.Controls.Add(f);
            }
            else if (AdmintreeView.SelectedNode.Text == "个人人事变动处理")
            {
                //MessageBox.Show("个人档案");
                this.Hide();
                ChangeForm f = new ChangeForm(adminname, id);
                f.ShowDialog();
                this.Dispose();
            }
            else if (AdmintreeView.SelectedNode.Text == "个人考核情况查询")
            {
                //MessageBox.Show("个人档案");
                datapanel.Controls.Clear();
                ExamSearchControl f = new ExamSearchControl();
                datapanel.Controls.Add(f);
            }
            else if (AdmintreeView.SelectedNode.Text == "个人考核情况处理")
            {
                //MessageBox.Show("个人档案");
                this.Hide();
                ExamForm f = new ExamForm(adminname, id);
                f.ShowDialog();
                this.Dispose();
            }
            else if (AdmintreeView.SelectedNode.Text == "签到查询")
            {
                //MessageBox.Show("个人档案");
                datapanel.Controls.Clear();
                SignsSearchControl f = new SignsSearchControl();
                datapanel.Controls.Add(f);
            }
            else if (AdmintreeView.SelectedNode.Text == "签到管理")
            {
                //MessageBox.Show("个人档案");
                this.Hide();
                SignsForm f = new SignsForm(adminname, id);
                f.ShowDialog();
                this.Dispose();
            }
            else if (AdmintreeView.SelectedNode.Text == "加班情况查询")
            {
                //MessageBox.Show("个人档案");
                datapanel.Controls.Clear();
                OvertimeSearchControl f = new OvertimeSearchControl();
                datapanel.Controls.Add(f);
            }
            else if (AdmintreeView.SelectedNode.Text == "加班情况管理")
            {
                //MessageBox.Show("个人档案");
                this.Hide();
                OvertimeForm f = new OvertimeForm(adminname, id);
                f.ShowDialog();
                this.Dispose();
            }
            else if (AdmintreeView.SelectedNode.Text == "出差情况查询")
            {
                //MessageBox.Show("个人档案");
                datapanel.Controls.Clear();
                OuttimeSearchControl f = new OuttimeSearchControl();
                datapanel.Controls.Add(f);
            }
            else if (AdmintreeView.SelectedNode.Text == "出差管理")
            {
                //MessageBox.Show("个人档案");
                this.Hide();
                OuttimeForm f = new OuttimeForm(adminname, id);
                f.ShowDialog();
                this.Dispose();
            }
        }


        //-----------------------------------
    }
}
